describe('Loading', () => {
  beforeEach(function() {
    this.$container = $('<div id="testContainer"></div>').appendTo('body');
  });

  afterEach(function() {
    if (this.$container) {
      destroy();
      this.$container.remove();
    }
  });

  it('should be possible to enable the plugin', async() => {
    handsontable({
      data: createSpreadsheetData(10, 10),
      loading: true,
    });

    const plugin = getPlugin('loading');

    expect(plugin.isEnabled()).toBe(true);
  });

  it('should be possible to disable the plugin', async() => {
    handsontable({
      data: createSpreadsheetData(10, 10),
      loading: true,
    });

    await updateSettings({
      loading: false,
    });

    const plugin = getPlugin('loading');

    expect(plugin.isEnabled()).toBe(false);
  });

  it('should enable dialog plugin when loading plugin is enabled', async() => {
    handsontable({
      data: createSpreadsheetData(10, 10),
      loading: true,
    });

    const dialogPlugin = getPlugin('dialog');

    expect(dialogPlugin.isEnabled()).toBe(true);
  });

  it('should update the loading settings via updateSettings', async() => {
    handsontable({
      data: createSpreadsheetData(10, 10),
      loading: true,
    });

    await updateSettings({
      loading: {
        title: 'Reloading...',
      },
    });

    const plugin = getPlugin('loading');

    plugin.show();

    const container = getLoadingContainerElement();

    expect(container.querySelector('.ht-loading__title').textContent).toBe('Reloading...');
  });

  it('should translate UI text when different language pack is used on init', async() => {
    handsontable({
      data: createSpreadsheetData(10, 10),
      language: 'pl-pl',
      loading: true,
    });

    const plugin = getPlugin('loading');

    plugin.show();

    const container = getLoadingContainerElement();

    expect(container.querySelector('.ht-loading__title').textContent).toBe('Ładowanie...');
  });

  it('should destroy the plugin', async() => {
    handsontable({
      data: createSpreadsheetData(10, 10),
      loading: true,
    });

    const plugin = getPlugin('loading');

    plugin.destroy();

    expect(plugin.enabled).toBe(null);
  });

  it('should hide loading plugin on updateSettings to false', async() => {
    handsontable({
      data: createSpreadsheetData(10, 10),
      loading: true,
    });

    await updateSettings({
      loading: false,
    });

    const plugin = getPlugin('loading');

    expect(plugin.isVisible()).toBe(false);
    expect(plugin.enabled).toBe(false);
  });

  it('should not shown Deprecated warning when loading plugin is enabled and theme is not classic (legacy)', async() => {
    const warnSpy = spyOn(console, 'warn');

    handsontable({
      data: createSpreadsheetData(10, 10),
      loading: true,
    });

    if (spec().loadedTheme === 'classic') {
      // eslint-disable-next-line max-len
      expect(warnSpy).toHaveBeenCalledWith('Deprecated: The stylesheet you are using is deprecated and will be removed in version 17.0. Please update your theme configuration to ensure compatibility with future releases.');
    } else {
      expect(warnSpy).not.toHaveBeenCalled();
    }
  });
});
